
class player_data {
  constructor() {
    this.power = 0;
    this.bomb = 3;
    this.life = 0;
    this.score = 0;
    // plane表示选中的飞机，0-5, -1表示未开始
    this.plane = -1;
    // 玩家选定飞机了
    this.selected = false;
    // 玩家飞机爆炸后，多久算正式死亡
    this.deadcd = 0;

    // 选飞机倒计时 9,8,7,...0
    this.selectcd = 9;
    this.selectcdinterval = 0;

    //飞机续力值
    this.charge = 0;

    //飞机控制数据
    this.ctrl = {};
  }
  startselect() {	// 这个玩家开始选飞机
    this.selectcd = 9;
    this.selectcdinterval = 0;
    this.selected = false;
    this.life = Const.FORCE_PLAYER_LIFE > 0 ? Const.FORCE_PLAYER_LIFE : 3;
  }

  startplayer() {
    if(this.life > 0) {
      this.life--;
      this.deadcd = 30;
      return true;
    }
    return false;
  }
  isalive() {
    return this.deadcd > 0;
  }
}

class player_glob {
  constructor() {
    this.coin = 5;

    // 几个玩家的配置数据
    this.pdata = [];

    // 6个可以选的飞机，记录是否被选。如果被选了，不能再选
    this.selectplane = [];
  }
  readCtrlSet(setData) {
    for(let i = 0; i < Const.MAX_PLAYER_PLANE; i++) {
      this.selectplane.push(false);
    }

    for(let i = 0; i < Const.MAX_PLAYER; i++) {
      this.pdata.push(new player_data());
      let itemSet = setData['Player' + (i + 1)];
      for(let key of Object.keys(itemSet)) {
        this.pdata[i].ctrl[key] = { key: itemSet[key], is_down: false, is_pressed: false };
      }
    }
  }
}
player_glob.inst = new player_glob();
